package com.jadows.tdog.message.action;

import com.jadows.tdog.constants.WebRTCActions;
import com.jadows.tdog.message.WsReqWrapper;
import com.jadows.tdog.message.annotations.Action;
import com.jadows.tdog.message.details.WebRTCCallMessage;
import com.jadows.tdog.message.details.WebRTCSDPMessage;
import com.jadows.tdog.message.handler.impl.WebRTCCallMessageHandler;
import com.jadows.tdog.message.handler.impl.WebRTCSDPMessageHandler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
@Slf4j
public class WebRTCActionsHandler {

    final WebRTCCallMessageHandler webRTCCallMessageHandler;
    final WebRTCSDPMessageHandler webRTCSDPMessageHandler;


    /**
     * 发起通话邀请、接收通话邀请
     */
    @Action({WebRTCActions.CALL, WebRTCActions.ACCEPT, WebRTCActions.REJECT, WebRTCActions.HANGUP})
    public void webRtcActions(WsReqWrapper<WebRTCCallMessage> reqWrapper) {
        webRTCCallMessageHandler.publish(reqWrapper);
    }

    /**
     * 媒体协商
     */
    @Action({WebRTCActions.OFFER, WebRTCActions.ANSWER, WebRTCActions.CANDIDATE})
    public void sdpActions(WsReqWrapper<WebRTCSDPMessage> reqWrapper) {
        webRTCSDPMessageHandler.publish(reqWrapper);
    }
}
